﻿using System.Runtime.Serialization;
using Framework.Core.Cache;
using Framework.Core.Reflection;

namespace Framework.Core.Recorder
{
    internal class CallKeyBuilder : ICallKeyBuilder
    {
        private readonly ICacheKeyBuilder cacheKeyBuilder;

        internal CallKeyBuilder(ICacheKeyBuilder cacheKeyBuilder)
        {
            this.cacheKeyBuilder = cacheKeyBuilder;
        }

        public CallKeyBuilder()
            : this(new CacheKeyBuilder(new HashProviderForLegacy()))
        {
        }

        public string Build(IMethod method)
        {
            try
            {
                return cacheKeyBuilder.Build(method);
            }
            catch (SerializationException ex)
            {
                throw new HardMockException(ex.Message);
            }
        }
    }
}